Skip to content

spi: aspeed: Respect transfer-specific bit width#5

Closed
mfield4 wants to merge 1 commit into
AspeedTech-BMC:aspeed-master-v6.18from
mfield4:spi-respect-txrx-nbits
Closed

spi: aspeed: Respect transfer-specific bit width#5
mfield4 wants to merge 1 commit into
AspeedTech-BMC:aspeed-master-v6.18from
mfield4:spi-respect-txrx-nbits

Conversation

@mfield4

@mfield4 mfield4 commented Jun 3, 2026

Copy link
Copy Markdown

The ASPEED SPI driver previously configured the controller's transfer mode (dual, quad, or single) based globally on the target device's capability flags (spi->mode & SPI_TX_DUAL/QUAD), ignoring the requested width of individual transfers in the message sequence. This deviates from the Linux SPI subsystem design, which expects command, address, and dummy phases of a transaction to default to single-bit transmission, with multi-bit mode restricted strictly to the data payload transfers that request it via tx_nbits or rx_nbits.

Fix this by dynamically adjusting the controller's IO mode for each transfer segment. The dual or quad IO mode is activated only if both the individual transfer requests the multi-bit width (tx_nbits/rx_nbits) and the device globally supports that mode (spi->mode). All other transfers remain in the default single-bit mode.

The ASPEED SPI driver previously configured the controller's transfer mode
(dual, quad, or single) based globally on the target device's capability
flags (spi->mode & SPI_TX_DUAL/QUAD), ignoring the requested width of
individual transfers in the message sequence. This deviates from the Linux
SPI subsystem design, which expects command, address, and dummy phases of
a transaction to default to single-bit transmission, with multi-bit mode
restricted strictly to the data payload transfers that request it via
tx_nbits or rx_nbits.

Fix this by dynamically adjusting the controller's IO mode for each
transfer segment. The dual or quad IO mode is activated only if both the
individual transfer requests the multi-bit width (tx_nbits/rx_nbits) and
the device globally supports that mode (spi->mode). All other transfers
remain in the default single-bit mode.
@mfield4 mfield4 marked this pull request as draft June 4, 2026 15:28
@hung-chu-huang

Copy link
Copy Markdown

Hi @mfield4,

Thanks for the patch — the intent is correct, and we appreciate you spotting this issue.

We have a fix for this queued in our internal tree with a slightly different approach.
Rather than checking both spi->mode flags and xfer->tx_nbits / xfer->rx_nbits, we check only the per-transfer nbits fields directly:

if (xfer->tx_nbits == SPI_NBITS_DUAL)
	ctrl_val |= SPI_DUAL_IO_MODE;
else if (xfer->tx_nbits == SPI_NBITS_QUAD)
	ctrl_val |= SPI_QUAD_IO_MODE;

The additional spi->mode check is unnecessary because the SPI core already validates xfer->tx_nbits / xfer->rx_nbits against the device's mode flags in __spi_validate() before the message reaches the driver.
For example, if xfer->tx_nbits == SPI_NBITS_DUAL but spi->mode does not have SPI_TX_DUAL set, the core returns -EINVAL and the transfer never reaches the driver.

Checking spi->mode again in the driver is therefore redundant duplication of what the core already guarantees.

We'll carry our version of this fix in our upcoming update, so we won't be merging this PR.
We'll make sure to credit you for pointing this out.
Thanks again for the contribution!

@mfield4

mfield4 commented Jun 11, 2026

Copy link
Copy Markdown
Author

Hi @hung-chu-huang,

I let this slip under the radar a bit, so this is a welcome surprise coming in this morning.

I appreciate the attribution, and will close the PR. Thank you so much!

@mfield4 mfield4 closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants